package com.pe1n.yangtaopai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.bean.ListthreeBean;
import com.pe1n.yangtaopai.page.find.view.activity.FindActivity;
import com.pe1n.yangtaopai.view.activity.ItemOneListActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/11/23.
 */

public class MyAmountItemThreeRecyclerAdapter extends RecyclerView.Adapter<MyAmountItemThreeRecyclerAdapter.MyViewItemHoler>{
    private Context context;
    private List<ListthreeBean.DataBean>listthreeBeen;

    public MyAmountItemThreeRecyclerAdapter(Context context, List<ListthreeBean.DataBean> listthreeBeen) {
        this.context = context;
        this.listthreeBeen = listthreeBeen;
    }


    @Override
    public int getItemCount() {
        return listthreeBeen.size();
    }
    @Override
    public MyViewItemHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_listthree_image_layout,parent,false);
        return new MyViewItemHoler(view);
    }

    @Override
    public void onBindViewHolder(MyViewItemHoler holder, final int position) {
        final ListthreeBean.DataBean bean=listthreeBeen.get(position);
        String urlString=bean.getImagePath();
        Glide.with(context)
                .load(urlString)
                .placeholder(R.drawable.place_holder)
                .into(holder.listthree_image);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (position==1){
                    Intent intent1=new Intent(context,FindActivity.class);
                      String id=listthreeBeen.get(position).getTargetId();
                      String title=listthreeBeen.get(position).getTitle();
                      intent1.putExtra("id",id);
                      intent1.putExtra("title",title);
                      context.startActivity(intent1);
                }else {
                    Intent intent=new Intent(context, ItemOneListActivity.class);
                      String id=listthreeBeen.get(position).getTargetId();
                      String OneImgTitle=listthreeBeen.get(position).getTitle();
                      //String name =listthreeBeen.get(position).getTitle();
                      intent.putExtra("ID",id);
                      intent.putExtra("OneImgTitle",OneImgTitle);

                    context.startActivity(intent);

                }
            }
        });


    }


    class MyViewItemHoler extends RecyclerView.ViewHolder{
        private ImageView listthree_image;

        public MyViewItemHoler(View itemView) {
            super(itemView);
            listthree_image = (ImageView) itemView.findViewById(R.id.item_listthree_image);

        }
    }
}
